package com.chixing.controller;


import com.chixing.pojo.CustomerTokenDTO;
import com.chixing.pojo.Evaluation;
import com.chixing.commons.ServerResponce;
import com.chixing.service.IEvaluationService;
import com.chixing.utils.TokenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.time.LocalDateTime;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author pyc
 * @since 2022-10-17
 */

@RestController
public class EvaluationController {

    @Autowired
    private IEvaluationService evaluationService;

    @PostMapping("/evaluation/fabiao")
    public ServerResponce saveFabiao(String evaluationDetil, Integer proId, Integer evaluationPoint, String token){

        System.out.println("token：" + token);

        Evaluation evaluation = new Evaluation();
        evaluation.setEvaluationLikeNums(1);
        evaluation.setEvaluationTime(String.valueOf(LocalDateTime.now()));
        evaluation.setEvaluationStatus(1);
        evaluation.setEvaluationVersion(1);
        evaluation.setEvaluationPoint(evaluationPoint);
        evaluation.setProductId(proId);
        evaluation.setUserId(TokenUtil.parseToken(token).getCustId());
        evaluation.setEvaluationDetil(evaluationDetil);

        Boolean result = evaluationService.save(evaluation);

        System.out.println(result);
        return ServerResponce.success("评论成功",evaluation);
    }

/*    @PostMapping("fabiao")
    public ModelAndView saveFabiao(@RequestParam("fop-neirong") String neirong){
        Evaluation evaluation = new Evaluation();
        evaluation.setEvaluationDetil(neirong);
        evaluation.setEvaluationPoint(BigDecimal.valueOf(5.0f));
        evaluation.setEvaluationLikeNums(5);
        evaluation.setEvaluationTime(String.valueOf(LocalDateTime.now()));
        evaluation.setEvaluationStatus(1);
        evaluation.setEvaluationVersion(1);
        evaluation.setProductId(1001);
        evaluation.setUserId(2);

        Boolean result = evaluationService.save(evaluation);

        System.out.println(result);
        return null;
    }*/

/*    @PostMapping("/dafen")
    public R addScord(@RequestBody PingFen pingFen) {
        System.out.println(pingFen.toString());
        return null;
    }*/
//,@RequestParam("propoint") BigDecimal propoint
}
